package com.swan.web.exception;

import com.swan.web.auto.config.WebConfig;
import com.swan.web.domain.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/** 系统默认未知异常处理器
 * @author zongf
 * @date 2025-02-08
 **/
@Slf4j
@Component
public class DefaultUnknownExceptionHandler implements IUnknownExceptionHandler{

    private BaseResponse baseResponse;

    public DefaultUnknownExceptionHandler(WebConfig webConfig) {
        baseResponse = new BaseResponse(webConfig.getException().getUnknownCode(), webConfig.getException().getUnknownMessage());
    }

    @Override
    public BaseResponse handle(Throwable throwable) {
        log.error("未知系统异常", throwable);
        return baseResponse;
    }

    @Override
    public Class<? extends Throwable> handleType() {
        return Throwable.class;
    }

    @Override
    public int getOrder() {
        // 作为兜底异常处理
        return Integer.MAX_VALUE;
    }
}
